package uk.co.kevinlockwood.kol.pages;

import java.util.List;

import uk.co.kevinlockwood.kol.JavaHelpers;
import uk.co.kevinlockwood.kol.droid.DroidHelpers;
import uk.co.kevinlockwood.kol.droid.G;
import uk.co.kevinlockwood.kol.messages.KoLMessage;

public class SubmitNewChat extends KoLPage {
	private Integer playerid;
	private String hash;
	private String msg;
	private KoLMessage rtn;

	public SubmitNewChat(Integer playerid, String hash, String msg) {
		this.playerid = playerid;
		this.hash = hash;
		this.msg = JavaHelpers.urlencode(msg);
		DroidHelpers.trace("message=[",msg,"] escaped=[",this.msg,"]");
	}

	public KoLMessage getReturnMessage() {
		return rtn;
	}

	@Override
	public String pageName() {
		StringBuilder sb = new StringBuilder(G.CHAT_MSG_BUFFER_LENGTH);
		sb.append("submitnewchat.php?playerid=");
		sb.append(playerid);
		sb.append("&pwd=");
		sb.append(hash);
		sb.append("&graf=");
		sb.append(msg);
		return sb.toString();
	}

	@Override
	public void buildFromHtml(List<String> html) {
		DroidHelpers.trace("Building SubmitNewChat");
		StringBuilder sb = new StringBuilder();
		for (String s : html) {
			DroidHelpers.log("got string [",s,"]");
			sb.append(s);
		}
		rtn = KoLMessage.parse(sb.toString());
		return;
	}
}
